package com.vne.skyemart.model;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

@Entity
@Table(name = "aduser",catalog = "skyemart_db")
public class ADUser implements Serializable{

	private static final long serialVersionUID = -3436197909986682355L;
	
	@Id                  
	@GeneratedValue                                                                               
	@Column(name = "UserID",nullable = false,unique = true)
	private int userID;
	
	@OneToMany(fetch = FetchType.LAZY,mappedBy = "adUser")
	private Set<Cart> cart  = new HashSet<Cart>(0);
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "UserTypeID", nullable = false)
	private UserType userType;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "adUser")
	private Set<UserLog> userLog = new HashSet<UserLog>(0);
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "adUser")
	private Set<Store> store = new HashSet<Store>(0);
	
	@ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
	@JoinTable(name="groupusers", catalog = "skyemart_db", joinColumns={@JoinColumn(name="UserID")}, inverseJoinColumns={@JoinColumn(name="GroupID")})
	private Set<Groups> groups = new HashSet<Groups>(0); 

	
	@Column(name = "Nationality",length = 20)
	private String nationality;

	
	@Column(name = "Phone",length = 20)
	private String phone;

	
	@Column(name = "Email",length = 50)
	private String email;


	@Column(name = "Fax",length = 50)
	private String fax;

	
	@Column(name = "IDCard",length = 20)
	private String iDCard;


	@Column(name = "Username",nullable = false, length = 20, unique = true)
	private String username;

	@Column(name = "Password",nullable = false, length = 32)
	private String password;

	
	@Column(name = "FullName",length = 50)
	private String fullName;

	@Column(name = "Gender",length = 1)
	private char gender;

	@Temporal(TemporalType.DATE)
	@Column(name = "DateOfBirth", length = 10)
	private Date dateOfBirth;

	
	@Column(name = "Address",length = 250)
	private String address;

	@Column(name = "CreatedBy",nullable = false)
	private int createdBy = 0;

	@Temporal(TemporalType.DATE)
	@Column(name = "CreatedDate",nullable = false)
	private Date createdDate;

	
	@Column(name = "ModifiedBy", nullable = true, length = 10)
	private int modifiedBy;

	@Temporal(TemporalType.DATE)
	@Column(name = "ModifiedDate", nullable = false)
	private Date modifiedDate;

	@Column(name = "IsActived", nullable = false)
	private String isActived;


	@Column(name = "IsDeleted", nullable = false)
	private String isDeleted;
	
	/***********************************************************************************************
	 * CONTRUSTOR
	 ***********************************************************************************************/
	public ADUser() {}

	public ADUser(int userID, UserType userType) {
		this.userID = userID;
		this.userType = userType;
	}
		
	public ADUser(int userID, UserType userType, Set<UserLog> userLog) {
		this.userID = userID;
		this.userType = userType;
		this.userLog = userLog;
	}

	
	public ADUser(int userID, UserType userType, Set<UserLog> userLog,
			Set<Groups> groups) {
		this.userID = userID;
		this.userType = userType;
		this.userLog = userLog;
		this.groups = groups;
	}

	/***********************************************************************************************
	 * GETTER AND SETTER
	 ***********************************************************************************************/
	public int getUserID() {
		return userID;
	}

	public void setUserID(int userID) {
		this.userID = userID;
	}

	public UserType getUserType() {
		return userType;
	}

	public void setUserType(UserType userType) {
		this.userType = userType;
	}
	
	public Set<UserLog> getUserLog() {
		return userLog;
	}
	
	public void setUserLog(Set<UserLog> userLog) {
		this.userLog = userLog;
	}
	
	public Set<Groups> getGroups() {
		return groups;
	}
	
	public void setGroups(Set<Groups> groups) {
		this.groups = groups;
	}

	public String getNationality() {
		return nationality;
	}

	public void setNationality(String nationality) {
		this.nationality = nationality;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getiDCard() {
		return iDCard;
	}

	public void setiDCard(String iDCard) {
		this.iDCard = iDCard;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getFullName() {
		return fullName;
	}

	public void setFullName(String fullName) {
		this.fullName = fullName;
	}

	public char getGender() {
		return gender;
	}

	public void setGender(char gender) {
		this.gender = gender;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public int getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(int createdBy) {
		this.createdBy = createdBy;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public int getModifiedBy() {
		return modifiedBy;
	}

	public void setModifiedBy(int modifiedBy) {
		this.modifiedBy = modifiedBy;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public String getIsActived() {
		return isActived;
	}

	public void setIsActived(String isActived) {
		this.isActived = isActived;
	}

	public String getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(String isDeleted) {
		this.isDeleted = isDeleted;
	}

	public Set<Store> getStores() {
		return store;
	}

	public void setStores(Set<Store> store) {
		this.store = store;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public Set<Cart> getCart() {
		return cart;
	}

	public void setCart(Set<Cart> cart) {
		this.cart = cart;
	}

	public Set<Store> getStore() {
		return store;
	}

	public void setStore(Set<Store> store) {
		this.store = store;
	}
	
}
